import 'dart:convert';
import 'dart:typed_data';

import 'package:bot_toast/bot_toast.dart';
import 'package:exams_app/login_module/real_name_authen/view.dart';
import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:exams_app/home_module/account_set_module/account_logic.dart';
import 'package:exams_app/widget/photoview_simplescreen.dart';

import 'logic.dart';

// class RenZhengInfoPage extends StatefulWidget {
//   const RenZhengInfoPage({Key key}) : super(key: key);
//
//   @override
//   _RenZhengInfoPageState createState() => _RenZhengInfoPageState();
// }

class RenZhengInfoPage extends StatelessWidget {

  final AccountLogic acclogic = Get.put(AccountLogic());
  final RealNameAuthenLogic realLogic = Get.put(RealNameAuthenLogic());


  var sfzHeads = '';
  var sfzTails = '' ;

  // var tf1 = TextEditingController();
  // var tf2 = TextEditingController();
  // var tf3 = TextEditingController();
  // var tf4 = TextEditingController();

  @override
  Widget build(BuildContext context) {



    // if(acclogic.json['data']!=null){
    //   tf1.text = acclogic.json['data'][0]['full_name'];
    //   tf2.text = acclogic.json['data'][0]['sfz'];
    //   setState(() {
    //
    //   });
    // }

    return Scaffold(
      appBar: AppBar(
        title: Text('认证信息'),
        actions: [
          TextButton(onPressed: (){

            Get.to(RealNameAuthenPage());

          }, child: Text('重新认证',style:TextStyle(color:Colors.white )),)
        ],
      ),
      body: GetBuilder<AccountLogic>(
        initState: (sz)async{

          Rx<RenZhenInfoModel> model = await  acclogic.requestDataWithUserInfo();
           realLogic. tf1.text = model.value.data[0].fullName;
          realLogic. tf2.text = model.value.data[0].sfz;
          realLogic.tf4.text = model.value.data[0].exam_company_name;
          realLogic. tf3.text = model.value.data[0].exam_project_name;


            sfzHeads = model.value.data[0].sfzHeads;
            sfzTails = model.value.data[0].sfzTails;
        },

      builder: (_) {



        return acclogic.rzmodel == null?Container(
          child: Center(
            child: CircularProgressIndicator(),
          ),
          color: Colors.white,
        ):ListView(
          children: [
            Container(
                height: 50,
                decoration: new BoxDecoration(
                  color: Colors.white,
                  //设置四周圆角 角度
                  borderRadius: BorderRadius.all(Radius.circular(22.0)),
                  //设置四周边框
                  border: new Border.all(width: 1, color: HexColor('#ECECEC')),

                ),
                padding: EdgeInsets.only(left: 15),
                margin: EdgeInsets.only(top: 20,left: 15,right: 15),
                // width: Get.width-100,
                child: Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 5),
                      child: Text('项目名称',style: TextStyle(fontSize: 16,color: HexColor('#333333')),),
                    ),

                    VerticalDivider(
                      indent: 10,
                      endIndent: 10,
                      color: HexColor('#DFDFDF'),
                      width: 2,
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 5),
                      width: Get.width-200,
                      child: TextField(
                        controller: realLogic.tf3,
                        enabled: false,
                        style: TextStyle(fontSize: 16),
                        decoration: InputDecoration(
                          // isCollapsed: true,
                          // contentPadding: EdgeInsets.only(top: 15),
                          hintText: '请输入项目名称',
                          hintStyle: TextStyle(fontSize: 16,color: HexColor('#BBBBBB')),
                          border: InputBorder.none,
                          // prefixIcon: Image.asset(A.assets_user,),
                        ),
                      ),
                    )
                  ],
                )
            ),

            Container(
                height: 50,
                decoration: new BoxDecoration(
                  color: Colors.white,
                  //设置四周圆角 角度
                  borderRadius: BorderRadius.all(Radius.circular(22.0)),
                  //设置四周边框
                  border: new Border.all(width: 1, color: HexColor('#ECECEC')),

                ),
                padding: EdgeInsets.only(left: 15),
                margin: EdgeInsets.only(top: 20,left: 15,right: 15),
                // width: Get.width-100,
                child: Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 5),
                      child: Text('公司名称',style: TextStyle(fontSize: 16,color: HexColor('#333333')),),
                    ),

                    VerticalDivider(
                      indent: 10,
                      endIndent: 10,
                      color: HexColor('#DFDFDF'),
                      width: 2,
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 5),
                      width: Get.width-200,
                      child: TextField(
                        controller: realLogic.tf4,
                        enabled: false,
                        style: TextStyle(fontSize: 16),
                        decoration: InputDecoration(
                          // isCollapsed: true,
                          // contentPadding: EdgeInsets.only(top: 15),
                          hintText: '请输入公司名称',
                          hintStyle: TextStyle(fontSize: 16,color: HexColor('#BBBBBB')),
                          border: InputBorder.none,
                          // prefixIcon: Image.asset(A.assets_user,),
                        ),
                      ),
                    )
                  ],
                )
            ),


            Container(
                height: 50,
                decoration: new BoxDecoration(
                  color: Colors.white,
                  //设置四周圆角 角度
                  borderRadius: BorderRadius.all(Radius.circular(22.0)),
                  //设置四周边框
                  border: new Border.all(width: 1, color: HexColor('#ECECEC')),

                ),
                padding: EdgeInsets.only(left: 15),
                margin: EdgeInsets.only(top: 20,left: 15,right: 15),
                // width: Get.width-100,
                child: Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 5),
                      child: Text('真实姓名',style: TextStyle(fontSize: 16,color: HexColor('#333333')),),
                    ),

                    VerticalDivider(
                      indent: 10,
                      endIndent: 10,
                      color: HexColor('#DFDFDF'),
                      width: 2,
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 5),
                      width: Get.width-200,
                      child: TextField(
                        controller: realLogic.tf1,
                        enabled: false,
                        style: TextStyle(fontSize: 16),
                        decoration: InputDecoration(
                          // isCollapsed: true,
                          // contentPadding: EdgeInsets.only(top: 15),
                          hintText: '请输入您的真是姓名',
                          hintStyle: TextStyle(fontSize: 16,color: HexColor('#BBBBBB')),
                          border: InputBorder.none,
                          // prefixIcon: Image.asset(A.assets_user,),
                        ),
                      ),
                    )
                  ],
                )
            ),
            Container(
                height: 50,
                decoration: new BoxDecoration(
                  color: Colors.white,
                  //设置四周圆角 角度
                  borderRadius: BorderRadius.all(Radius.circular(22.0)),
                  //设置四周边框
                  border: new Border.all(width: 1, color: HexColor('#ECECEC')),

                ),
                padding: EdgeInsets.only(left: 15),
                margin: EdgeInsets.only(top: 20,left: 15,right: 0),
                // width: Get.width-100,
                child: Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 5),
                      child: Text('身份证号',style: TextStyle(fontSize: 16,color: HexColor('#333333')),),
                    ),

                    VerticalDivider(
                      indent: 10,
                      endIndent: 10,
                      color: HexColor('#DFDFDF'),
                      width: 2,
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 5),
                      width: Get.width-150,
                      child: TextField(
                        controller:realLogic. tf2,
                        enabled: false,
                        style: TextStyle(fontSize: 16),
                        decoration: InputDecoration(
                          // isCollapsed: true,
                          // contentPadding: EdgeInsets.only(top: 15),
                          hintText: '请输入身份证号码',
                          hintStyle: TextStyle(fontSize: 16,color: HexColor('#BBBBBB')),
                          border: InputBorder.none,
                          // prefixIcon: Image.asset(A.assets_user,),
                        ),
                      ),
                    )
                  ],
                )
            ),

            Container(
              margin: EdgeInsets.only(top: 25,left: 20),
              child: Text('已认证信息',style: TextStyle(fontSize: 18,color: HexColor('#333333'),fontWeight: FontWeight.w500),),
            ),

            Container(
              alignment: Alignment.center,
              // color: Colors.red,
              child: Row(
                // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                 Expanded(child:  Column(
                   children: [
                     GestureDetector(
                       onTap: (){

                         Navigator.push(
                           context,
                           MaterialPageRoute(fullscreenDialog: false,
                             builder: (_) => PhotoViewSimpleScreen(imageProvider:  MemoryImage(Uint8List.fromList(base64Decode(
                               sfzHeads))),heroTag: 'simple',),
                             // settings: RouteSettings(isInitialRoute: true),
//                    fullscreenDialog: true,
                           ),
                         );

                         // Get.to(PhotoViewSimpleScreen(imageProvider: MemoryImage(Uint8List.fromList(base64Decode(
                         //     sfzHeads))),heroTag: 'simple',),transition:Transition.fade);

                         // Navigator.of(context).push(new FadeRoute(page: PhotoViewSimpleScreen(
                         //   imageProvider:MemoryImage(Uint8List.fromList(base64Decode(
                         //        sfzHeads))),
                         //   heroTag: 'simple',
                         // )));
                       },
                       child: Hero(
                         tag: 'simple',
                         child: Container(
                           color: Colors.red,
                           margin: EdgeInsets.all(5),
                           child: Image.memory(
                             Uint8List.fromList(base64Decode(
                                 sfzHeads)),
                             fit: BoxFit.fill,
                           ),
                           height: 100,
                           // width: 200,
                         ),
                       )
                     ),
                     Text('身份证正面照')
                   ],
                 ),),
                 Expanded(child:  Column(
                   children: [
                     GestureDetector(
                       onTap: (){
                         Get.to(PhotoViewSimpleScreen(imageProvider: MemoryImage(Uint8List.fromList(base64Decode(
                             sfzTails))),heroTag: 'simple2',),transition:Transition.fade);
                       },
                       child:Hero(
                         tag: 'simple2',
                         child:  Container(
                           color: Colors.red,
                           child: Image.memory(
                             Uint8List.fromList(base64Decode(
                                 sfzTails)),
                             fit: BoxFit.fill,
                           ),
                           height: 100,
                           // width: 200,
                         ),
                       ),
                     ),
                     Text('身份证反面照')
                   ],
                 ),),

                ],
              ),
              margin: EdgeInsets.only(left: 0),
            ),

            Column(
              children: [
                GestureDetector(
                  onTap: (){
                    Get.to(PhotoViewSimpleScreen(imageProvider: MemoryImage(Uint8List.fromList(base64Decode(
                        '${ acclogic.rzmodel.value.data[0].aiFace}'))),heroTag: 'simple3',),transition:Transition.fade);
                  },
                  child: Hero(
                    tag: 'simple3',
                    child: Container(
                      child: Image.memory(
                        Uint8List.fromList(base64Decode(
                            '${ acclogic.rzmodel.value.data[0].aiFace}')),
                        fit: BoxFit.contain,
                      ),
                      height: 200,
                      width: 100,
                    ),
                  )
                ),
                Text('人脸采集')
              ],
            ),

          ],

        );
  },
),
    );
  }
}
class FadeRoute extends PageRouteBuilder {
  final Widget page;
  FadeRoute({this.page}): super(
    pageBuilder: (
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
        ) =>page,transitionsBuilder: (
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      Widget child,
      ) =>FadeTransition(
    opacity: animation,
    child: child,
  ),
  );
}

